package com.mine.site.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mine.site.dao.UserDao;
import com.mine.site.model.bsUser;

/**
 * Servlet implementation class BsLoginServlet
 */
@WebServlet("/BsLoginServlet")
public class BsLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BsLoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@SuppressWarnings("unused")
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		       request.setCharacterEncoding("utf-8");
		       response.setContentType("text/html");
		       PrintWriter out = response.getWriter();
		       String name = new String (request.getParameter("name").getBytes("ISO8859-1"),"utf-8");
		       String pwd = new String (request.getParameter("loginPwd").getBytes("ISO8859-1"),"utf-8");
		       
		       UserDao dao = new UserDao();
		       bsUser u = dao.findByname1(name);
		       
		       if(u != null  && u.getLoginPwd().equals(pwd)){
		    	   request.getSession().setAttribute("bsloginUser", u);
		    	   response.sendRedirect("bsServlet");
		       }else{
		    	   response.sendRedirect("bsLogin.jsp");
		       }
		   
	}
	}

